package com.playball.lottery.frm.kjinfo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Html;
import android.text.Spanned;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

import com.playball.lottery.R;
import com.playball.lottery.ApplicationData;
import com.playball.lottery.base.BaseActivity;
import com.playball.lottery.customview.ShowTipDialog;
import com.playball.lottery.frm.buyhall.CtzqRx9Activity;
import com.playball.lottery.frm.buyhall.CtzqSfcActivity;
import com.playball.lottery.nt.orjdd.GetRequestParams;
import com.playball.lottery.util.ConvertJsonToList;
import com.playball.lottery.util.DateUtil;
import com.playball.lottery.util.DefConstants;
import com.playball.lottery.util.KaiJiangUtil;
import com.playball.lottery.util.SysApplication;


/**
 * 开奖单期中奖详情
 * 
 * @author Administrator
 * 
 */
public class KjinfoListDetail extends BaseActivity implements DefConstants {
	/** 上下文内容 */
	private Context context = null;
	private Map<String, Object> mData;
	private ShowTipDialog showdialog = new ShowTipDialog();
	List<Map<String, Object>> awardList = new ArrayList<Map<String, Object>>();

	private TextView topTitleView;
	private TextView startView;// 开奖日期
	private TextView endView;
	private TextView numberView;
	private TextView blueNumberView;
	private TextView allmoneyView;
	private TextView salesView;
	/** 期次 */
	private TextView tvQICI;

	private String lottID;
	private String lottName;
	private String Issue;
	private String IssueID;

	private String openDate;
	private String endDate;
	private String number;
	private String Wins;
	private String salesMoney;
	private String allMoney;

	private View otherPar;
	private View sfcPar;
	private TextView tv_sfcAllMoney;
	private TextView tv_sfcSalesMoney;
	// private TextView tv_rx9AllMoney;
	private TextView tv_rx9SalesMoney;
	private String sfcAllMoney;
	private String sfcSalesMoney;
	private String rx9AllMoney;
	private String rx9SalesMoney;

	private TextView tv_Hteam1;
	private TextView tv_Hteam2;
	private TextView tv_Hteam3;
	private TextView tv_Hteam4;
	private TextView tv_Hteam5;
	private TextView tv_Hteam6;
	private TextView tv_Hteam7;
	private TextView tv_Hteam8;
	private TextView tv_Hteam9;
	private TextView tv_Hteam10;
	private TextView tv_Hteam11;
	private TextView tv_Hteam12;
	private TextView tv_Hteam13;
	private TextView tv_Hteam14;

	private TextView tv_Vteam1;
	private TextView tv_Vteam2;
	private TextView tv_Vteam3;
	private TextView tv_Vteam4;
	private TextView tv_Vteam5;
	private TextView tv_Vteam6;
	private TextView tv_Vteam7;
	private TextView tv_Vteam8;
	private TextView tv_Vteam9;
	private TextView tv_Vteam10;
	private TextView tv_Vteam11;
	private TextView tv_Vteam12;
	private TextView tv_Vteam13;
	private TextView tv_Vteam14;

	private TextView tv_score1;
	private TextView tv_score2;
	private TextView tv_score3;
	private TextView tv_score4;
	private TextView tv_score5;
	private TextView tv_score6;
	private TextView tv_score7;
	private TextView tv_score8;
	private TextView tv_score9;
	private TextView tv_score10;
	private TextView tv_score11;
	private TextView tv_score12;
	private TextView tv_score13;
	private TextView tv_score14;

	// boolean isBackToMF = false;
	private Button kjinfo_info_btnzixuan;
	private Button kjinfo_info_btnjixuan;
	/** 开奖详情 */
	private Button kjinfo_detail_bt_kjxq;
	/** 开奖详情 奖级对照 中间分割线 */
	private View kjinfo_detail_line_jjdz;
	/** 奖级对照 */
	private Button kjinfo_detail_bt_jjdz;
	/** 中奖条件 注数 */
	private TextView winning;
	/** 双色球底部菜单栏 */
	private RelativeLayout kjinfo_rl_footssq;
	/** 胜负彩任选九底部菜单栏 */
	private RelativeLayout kjinfo_rl_foottosfcrx9;
	/** 去投胜负彩 */
	private Button kjinfo_btn_tosfc;
	/** 去投任九场 */
	private Button kjinfo_btn_torx9;

	private ListView kjinfo_info_lv1;
	private ListView kjinfo_info_lv2;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.context = this;
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.kjinfo_info);
		SysApplication.getInstance().addActivity(this);
		initView();
		Intent intent = getIntent();
		lottID = intent.getStringExtra("LottID");
		lottName = intent.getStringExtra("LottName");
		Issue = intent.getStringExtra("Issue");
		IssueID = intent.getStringExtra("IssueID");
		// isBackToMF = false;
		// isBackToMF = intent.getBooleanExtra("isBackToMF", false);
		if (lottID.equals("1")) {// 胜负彩ID=1
			otherPar.setVisibility(View.GONE);
			sfcPar.setVisibility(View.VISIBLE);
		} else {
			otherPar.setVisibility(View.VISIBLE);
			sfcPar.setVisibility(View.GONE);
		}
		// 显示胜负彩任选九专用底部菜单
		if (lottID.equals("1") || lottID.equals("19")) {// 胜负彩ID=1
			// kjinfo_rl_footssq.setVisibility(View.GONE);
			// kjinfo_rl_foottosfcrx9.setVisibility(View.VISIBLE);
			// 无奖级对照
			kjinfo_detail_line_jjdz.setVisibility(View.GONE);
			kjinfo_detail_bt_jjdz.setVisibility(View.GONE);
			kjinfo_detail_bt_kjxq.setSelected(true);
			// kjinfo_detail_bt_kjxq.setClickable(false);
		} else {
			// kjinfo_rl_footssq.setVisibility(View.VISIBLE);
			// kjinfo_rl_foottosfcrx9.setVisibility(View.GONE);
			// 有奖级对照
			kjinfo_detail_line_jjdz.setVisibility(View.VISIBLE);
			kjinfo_detail_bt_jjdz.setVisibility(View.VISIBLE);
			kjinfo_detail_bt_kjxq.setSelected(true);
			// kjinfo_detail_bt_kjxq.setClickable(true);
		}

		// 双色球 大乐透 有奖级对照
		if (lottID.equals("5") || lottID.equals("39")) {
			kjinfo_detail_line_jjdz.setVisibility(View.VISIBLE);
			kjinfo_detail_bt_jjdz.setVisibility(View.VISIBLE);
		} else {
			kjinfo_detail_line_jjdz.setVisibility(View.GONE);
			kjinfo_detail_bt_jjdz.setVisibility(View.GONE);
		}

		AsyncLoader task = new AsyncLoader();
		task.execute(lottID, IssueID, "302");
		// 标题
		TitleBar();

		setBtnOnClick(R.id.kjinfo_detail_bt_kjxq);
		setBtnOnClick(R.id.kjinfo_detail_bt_jjdz);

		kjinfo_info_btnjixuan.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				// Log.d("kjdetail", "机选");
				Intent intent;
				Class<?> activity = null;
				activity = KaiJiangUtil.getZiXuanActivity(Integer.parseInt(lottID));
				intent = new Intent();
				intent.putExtra("LotID", Integer.parseInt(lottID));
				intent.putExtra("isfromkaiJiang", 1);
				intent.setClass(KjinfoListDetail.this, activity);
				startActivity(intent);
			}
		});

		kjinfo_info_btnzixuan.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				// 数字彩
				Class<?> activity = null;
				activity = KaiJiangUtil.getZiXuanActivity(Integer.parseInt(lottID));
				// Log.d("kjdetail", "自选");
				Intent intent = new Intent(KjinfoListDetail.this, activity);
				startActivity(intent);
				// finish();
			}
		});

		kjinfo_btn_tosfc.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				// Log.d("kjdetail", "tosfc");
				Intent intent = new Intent(KjinfoListDetail.this, CtzqSfcActivity.class);
				startActivity(intent);
			}
		});

		kjinfo_btn_torx9.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				// Log.d("kjdetail", "torx9");
				Intent intent = new Intent(KjinfoListDetail.this, CtzqRx9Activity.class);
				startActivity(intent);
			}
		});
	}

	public void onResume() {
		super.onResume();
		
	}

	public void onPause() {
		super.onPause();
		
	}

	private void initView() {
		startView = (TextView) findViewById(R.id.kjinfo_detail_start);
		endView = (TextView) findViewById(R.id.kjinfo_detail_end);
		numberView = (TextView) findViewById(R.id.kjinfo_detail_number);
		blueNumberView = (TextView) findViewById(R.id.kjinfo_detail_number_blue);
		allmoneyView = (TextView) findViewById(R.id.kjinfo_detail_allmoney);
		salesView = (TextView) findViewById(R.id.kjinfo_detail_sales);
		otherPar = findViewById(R.id.kjinfo_list_detail_other_par);
		sfcPar = findViewById(R.id.kjinfo_list_detail_sfc_par);
		tv_sfcAllMoney = (TextView) findViewById(R.id.kjinfo_sfc_detail_allmoney);
		tv_sfcSalesMoney = (TextView) findViewById(R.id.kjinfo_sfc_detail_sales);
		tv_rx9SalesMoney = (TextView) findViewById(R.id.kjinfo_rx9_detail_sales);

		tvQICI = (TextView) findViewById(R.id.kjinfo_detail_qici);

		tv_Hteam1 = (TextView) findViewById(R.id.kjinfo_hteam_1);
		tv_Hteam2 = (TextView) findViewById(R.id.kjinfo_hteam_2);
		tv_Hteam3 = (TextView) findViewById(R.id.kjinfo_hteam_3);
		tv_Hteam4 = (TextView) findViewById(R.id.kjinfo_hteam_4);
		tv_Hteam5 = (TextView) findViewById(R.id.kjinfo_hteam_5);
		tv_Hteam6 = (TextView) findViewById(R.id.kjinfo_hteam_6);
		tv_Hteam7 = (TextView) findViewById(R.id.kjinfo_hteam_7);
		tv_Hteam8 = (TextView) findViewById(R.id.kjinfo_hteam_8);
		tv_Hteam9 = (TextView) findViewById(R.id.kjinfo_hteam_9);
		tv_Hteam10 = (TextView) findViewById(R.id.kjinfo_hteam_10);
		tv_Hteam11 = (TextView) findViewById(R.id.kjinfo_hteam_11);
		tv_Hteam12 = (TextView) findViewById(R.id.kjinfo_hteam_12);
		tv_Hteam13 = (TextView) findViewById(R.id.kjinfo_hteam_13);
		tv_Hteam14 = (TextView) findViewById(R.id.kjinfo_hteam_14);
		tv_Vteam1 = (TextView) findViewById(R.id.kjinfo_vteam_1);
		tv_Vteam2 = (TextView) findViewById(R.id.kjinfo_vteam_2);
		tv_Vteam3 = (TextView) findViewById(R.id.kjinfo_vteam_3);
		tv_Vteam4 = (TextView) findViewById(R.id.kjinfo_vteam_4);
		tv_Vteam5 = (TextView) findViewById(R.id.kjinfo_vteam_5);
		tv_Vteam6 = (TextView) findViewById(R.id.kjinfo_vteam_6);
		tv_Vteam7 = (TextView) findViewById(R.id.kjinfo_vteam_7);
		tv_Vteam8 = (TextView) findViewById(R.id.kjinfo_vteam_8);
		tv_Vteam9 = (TextView) findViewById(R.id.kjinfo_vteam_9);
		tv_Vteam10 = (TextView) findViewById(R.id.kjinfo_vteam_10);
		tv_Vteam11 = (TextView) findViewById(R.id.kjinfo_vteam_11);
		tv_Vteam12 = (TextView) findViewById(R.id.kjinfo_vteam_12);
		tv_Vteam13 = (TextView) findViewById(R.id.kjinfo_vteam_13);
		tv_Vteam14 = (TextView) findViewById(R.id.kjinfo_vteam_14);
		tv_score1 = (TextView) findViewById(R.id.kjinfo_score_1);
		tv_score2 = (TextView) findViewById(R.id.kjinfo_score_2);
		tv_score3 = (TextView) findViewById(R.id.kjinfo_score_3);
		tv_score4 = (TextView) findViewById(R.id.kjinfo_score_4);
		tv_score5 = (TextView) findViewById(R.id.kjinfo_score_5);
		tv_score6 = (TextView) findViewById(R.id.kjinfo_score_6);
		tv_score7 = (TextView) findViewById(R.id.kjinfo_score_7);
		tv_score8 = (TextView) findViewById(R.id.kjinfo_score_8);
		tv_score9 = (TextView) findViewById(R.id.kjinfo_score_9);
		tv_score10 = (TextView) findViewById(R.id.kjinfo_score_10);
		tv_score11 = (TextView) findViewById(R.id.kjinfo_score_11);
		tv_score12 = (TextView) findViewById(R.id.kjinfo_score_12);
		tv_score13 = (TextView) findViewById(R.id.kjinfo_score_13);
		tv_score14 = (TextView) findViewById(R.id.kjinfo_score_14);

		kjinfo_info_btnzixuan = (Button) findViewById(R.id.kjinfo_info_btnzixuan);
		kjinfo_info_btnjixuan = (Button) findViewById(R.id.kjinfo_info_btnjixuan);
		kjinfo_detail_bt_kjxq = (Button) findViewById(R.id.kjinfo_detail_bt_kjxq);
		kjinfo_detail_line_jjdz = (View) findViewById(R.id.kjinfo_detail_line_jjdz);
		kjinfo_detail_bt_jjdz = (Button) findViewById(R.id.kjinfo_detail_bt_jjdz);
		// kjinfo_detail_bt_kjxq.setSelected(false);
		winning = (TextView) findViewById(R.id.winning);
		kjinfo_rl_footssq = (RelativeLayout) findViewById(R.id.kjinfo_rl_footssq);
		kjinfo_rl_foottosfcrx9 = (RelativeLayout) findViewById(R.id.kjinfo_rl_foottosfcrx9);
		kjinfo_btn_tosfc = (Button) findViewById(R.id.kjinfo_btn_tosfc);
		kjinfo_btn_torx9 = (Button) findViewById(R.id.kjinfo_btn_torx9);

		kjinfo_info_lv1 = (ListView) findViewById(R.id.kjinfo_info_lv1);
		kjinfo_info_lv2 = (ListView) findViewById(R.id.kjinfo_info_lv2);
	}

	public class AsyncLoader extends AsyncTask<String, Integer, String> {// 继承AsyncTask

		// 1.准备运行
		protected void onPreExecute() {
			showdialog.showDialog(KjinfoListDetail.this);
		}

		// 2.正在后台运行
		protected String doInBackground(String... params) {
			String strResult = null;
			try {
				// 处理后台执行的任务，在后台线程执行
				JSONObject param = new JSONObject();
				param.put("LottID", params[0]);
				param.put("IssueID", params[1]);
				// 设置请求action
				String action = params[2];
				// 获取请求返回值
				strResult = GetRequestParams.getRequestResult(param.toString(), action, getApplicationContext());
			} catch (Exception e) {
				// TODO: handle exception
				Log.e("error", e.toString());
			}
			return strResult;
		}

		// 3.进度更新
		protected void onProgressUpdate(Integer... progress) {
		}

		// 4.完成后台任务
		protected void onPostExecute(String result) {
			if (result != null) {
				// Toast.LENGTH_LONG).show();
				try {
					JSONTokener jsonParser = new JSONTokener(result);
					JSONObject js = (JSONObject) jsonParser.nextValue();
					// 接下来的就是JSON对象的操作了
					if (Integer.parseInt(js.getString("Code")) == 0) {
						mData = getData(result);
						showDetailData();
						showdialog.closeDialog();
					} else {
						Toast.makeText(KjinfoListDetail.this, js.getString("Data"), Toast.LENGTH_SHORT).show();
					}
				} catch (JSONException ex) {
					// 异常处理代码
					Log.e("error", ex.toString());
				} finally {
					showdialog.closeDialog();
				}
			} else {
				Toast.makeText(KjinfoListDetail.this, getString(R.string.problem_01), Toast.LENGTH_LONG).show();
			}
		}

		// 5.完成后操作
		protected void onCancelled() {
		}
	}

	private Map<String, Object> getData(String strResult) {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			JSONTokener jsonParser = new JSONTokener(strResult);
			JSONObject js = (JSONObject) jsonParser.nextValue();
			map = ConvertJsonToList.getMap(js.getString("Data"));
		} catch (JSONException ex) {
			// 异常处理代码
			// ex.printStackTrace();
		}
		return map;
	}

	/**
	 * 显示页面详情信息
	 */
	public void showDetailData() {
		// 开奖日期//服务器新接口无开奖日期数据，根据兑奖截止日期推算出开奖日期,60day?
		openDate = mData.get("EndTime").toString();
		startView.setText(DateUtil.getDateTime3(openDate));
		// 期次
		tvQICI.setText(Issue);
		// 兑奖截止日期
		endDate = mData.get("EndTime").toString();// GetEndDate
		endView.setText(DateUtil.getDateAfterDay(openDate, 60));
		// 开奖号码
		number = mData.get("Number").toString();// WinNumber ssq 03 11 15 19 20
												// 31 + 07
		String[] nums = number.split("\\+");
		// Log.d("kjdetail", "number= "+number);
		// numberView.setText(nums[0]);
		// blueNumberView.setText(nums.length > 1 ? "+ " + nums[1] : "");
		// sfc WinNumber 33333333303030
		if (!lottID.equals("1") && !lottID.equals("19")) {// sfc WinNumber
															// 33333333303030
			LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
			layoutParams.gravity = Gravity.CENTER_VERTICAL;
			layoutParams.rightMargin = 5;
			LayoutInflater inflater = LayoutInflater.from(this);
			LinearLayout ballLayout = (LinearLayout) findViewById(R.id.kjinfo_list_detail_balllayout);
			// String[] redBall = nums[0].split(" ");
			String redBTemp, blueBTemp;
			redBTemp = nums[0];
			if (nums.length > 1) {
				blueBTemp = nums[1];
			} else {
				blueBTemp = "";
			}
			int lotIdInt = Integer.parseInt(lottID);
			if (lotIdInt == 3 || lotIdInt == 6 || lotIdInt == 63 || lotIdInt == 64) {
				char[] cs = redBTemp.toCharArray();
				if (cs.length > 2 && cs[1] != ' ') {
					redBTemp = "";
					for (int i = 0; i < cs.length; i++) {
						if (i == 0) {
							redBTemp = redBTemp + cs[0];
						} else {
							redBTemp = redBTemp + " " + cs[i];
						}
					}
				}
				cs = blueBTemp.toCharArray();
				blueBTemp = "";
				for (int i = 0; i < cs.length; i++) {
					if (i == 0) {
						blueBTemp = blueBTemp + cs[0];
					} else {
						blueBTemp = blueBTemp + " " + cs[i];
					}
				}
			}

			String[] redBall = redBTemp.split(" ");
			for (String ball : redBall) {
				TextView button = (TextView) inflater.inflate(R.layout.kjinfo_detail_item_ball, null);
				button.setText(ball);
				// button.setTextColor(getResources().getColor(R.color.ui_new_btn_yes_normal_solid));
				// button.setBackgroundResource(R.drawable.redball_normal);
				button.setTextColor(getResources().getColor(R.color.white));
				button.setBackgroundResource(R.drawable.redball_selected);
				ballLayout.addView(button, layoutParams);
			}
			// String blueBTemp;
			// if(nums.length>1){
			// blueBTemp= nums[1];
			// }else{
			// blueBTemp= "";
			// }
			// Log.d("KjinfoListDetail", "篮球blueBTemp="+blueBTemp);
			String[] blueBall = blueBTemp.split(" ");
			for (String ball : blueBall) {
				if (!"".equals(ball)) {
					TextView button = (TextView) inflater.inflate(R.layout.kjinfo_detail_item_ball, null);
					button.setText(ball);
					// button.setTextColor(getResources().getColor(R.color.ui_new_btn_no_normal_solid));
					// button.setBackgroundResource(R.drawable.blueball_normal);
					button.setTextColor(getResources().getColor(R.color.white));
					button.setBackgroundResource(R.drawable.blueball_selected);
					ballLayout.addView(button, layoutParams);
				}
			}
		}
		// 本期销量
		if ((lottID.equals("1") || lottID.equals("19"))) {
			tv_sfcSalesMoney.setText(addForeColorSpan(mData.get("Sales") + ""));
			tv_rx9SalesMoney.setText(addForeColorSpan(mData.get("R9Sales") + ""));

			Wins = mData.get("Matchs") + "";
			if (Wins.length() <= 1) {
				return;
			}

			// tv_sfcSalesMoney.setText(mData.get("Sales").toString() + "彩豆");
			// tv_rx9SalesMoney.setText(mData.get("R9Sales").toString() + "彩豆");
			List<Map<String, Object>> data = ConvertJsonToList.getList(Wins);
			if (data.size() == 14) {
				tv_Hteam1.setText((data.get(0).get("HTeam").toString() == null ? "" : data.get(0).get("HTeam")
						.toString()));
				tv_Vteam1.setText((data.get(0).get("VTeam").toString() == null ? "" : data.get(0).get("VTeam")
						.toString()));
				tv_score1.setText((data.get(0).get("Result").toString() == null ? "" : data.get(0).get("Result")
						.toString()));

				tv_Hteam2.setText((data.get(1).get("HTeam").toString() == null ? "" : data.get(1).get("HTeam")
						.toString()));
				tv_Vteam2.setText((data.get(1).get("VTeam").toString() == null ? "" : data.get(1).get("VTeam")
						.toString()));
				tv_score2.setText((data.get(1).get("Result").toString() == null ? "" : data.get(1).get("Result")
						.toString()));

				tv_Hteam3.setText((data.get(2).get("HTeam").toString() == null ? "" : data.get(2).get("HTeam")
						.toString()));
				tv_Vteam3.setText((data.get(2).get("VTeam").toString() == null ? "" : data.get(2).get("VTeam")
						.toString()));
				tv_score3.setText((data.get(2).get("Result").toString() == null ? "" : data.get(2).get("Result")
						.toString()));

				tv_Hteam4.setText((data.get(3).get("HTeam").toString() == null ? "" : data.get(3).get("HTeam")
						.toString()));
				tv_Vteam4.setText((data.get(3).get("VTeam").toString() == null ? "" : data.get(3).get("VTeam")
						.toString()));
				tv_score4.setText((data.get(3).get("Result").toString() == null ? "" : data.get(3).get("Result")
						.toString()));

				tv_Hteam5.setText((data.get(4).get("HTeam").toString() == null ? "" : data.get(4).get("HTeam")
						.toString()));
				tv_Vteam5.setText((data.get(4).get("VTeam").toString() == null ? "" : data.get(4).get("VTeam")
						.toString()));
				tv_score5.setText((data.get(4).get("Result").toString() == null ? "" : data.get(4).get("Result")
						.toString()));

				tv_Hteam6.setText((data.get(5).get("HTeam").toString() == null ? "" : data.get(5).get("HTeam")
						.toString()));
				tv_Vteam6.setText((data.get(5).get("VTeam").toString() == null ? "" : data.get(5).get("VTeam")
						.toString()));
				tv_score6.setText((data.get(5).get("Result").toString() == null ? "" : data.get(5).get("Result")
						.toString()));

				tv_Hteam7.setText((data.get(6).get("HTeam").toString() == null ? "" : data.get(6).get("HTeam")
						.toString()));
				tv_Vteam7.setText((data.get(6).get("VTeam").toString() == null ? "" : data.get(6).get("VTeam")
						.toString()));
				tv_score7.setText((data.get(6).get("Result").toString() == null ? "" : data.get(6).get("Result")
						.toString()));

				tv_Hteam8.setText((data.get(7).get("HTeam").toString() == null ? "" : data.get(7).get("HTeam")
						.toString()));
				tv_Vteam8.setText((data.get(7).get("VTeam").toString() == null ? "" : data.get(7).get("VTeam")
						.toString()));
				tv_score8.setText((data.get(7).get("Result").toString() == null ? "" : data.get(7).get("Result")
						.toString()));

				tv_Hteam9.setText((data.get(8).get("HTeam").toString() == null ? "" : data.get(8).get("HTeam")
						.toString()));
				tv_Vteam9.setText((data.get(8).get("VTeam").toString() == null ? "" : data.get(8).get("VTeam")
						.toString()));
				tv_score9.setText((data.get(8).get("Result").toString() == null ? "" : data.get(8).get("Result")
						.toString()));

				tv_Hteam10.setText((data.get(9).get("HTeam").toString() == null ? "" : data.get(9).get("HTeam")
						.toString()));
				tv_Vteam10.setText((data.get(9).get("VTeam").toString() == null ? "" : data.get(9).get("VTeam")
						.toString()));
				tv_score10.setText((data.get(9).get("Result").toString() == null ? "" : data.get(9).get("Result")
						.toString()));

				tv_Hteam11.setText((data.get(10).get("HTeam").toString() == null ? "" : data.get(10).get("HTeam")
						.toString()));
				tv_Vteam11.setText((data.get(10).get("VTeam").toString() == null ? "" : data.get(10).get("VTeam")
						.toString()));
				tv_score11.setText((data.get(10).get("Result").toString() == null ? "" : data.get(10).get("Result")
						.toString()));

				tv_Hteam12.setText((data.get(11).get("HTeam").toString() == null ? "" : data.get(11).get("HTeam")
						.toString()));
				tv_Vteam12.setText((data.get(11).get("VTeam").toString() == null ? "" : data.get(11).get("VTeam")
						.toString()));
				tv_score12.setText((data.get(11).get("Result").toString() == null ? "" : data.get(11).get("Result")
						.toString()));

				tv_Hteam13.setText((data.get(12).get("HTeam").toString() == null ? "" : data.get(12).get("HTeam")
						.toString()));
				tv_Vteam13.setText((data.get(12).get("VTeam").toString() == null ? "" : data.get(12).get("VTeam")
						.toString()));
				tv_score13.setText((data.get(12).get("Result").toString() == null ? "" : data.get(12).get("Result")
						.toString()));

				tv_Hteam14.setText((data.get(13).get("HTeam").toString() == null ? "" : data.get(13).get("HTeam")
						.toString()));
				tv_Vteam14.setText((data.get(13).get("VTeam").toString() == null ? "" : data.get(13).get("VTeam")
						.toString()));
				tv_score14.setText((data.get(13).get("Result").toString() == null ? "" : data.get(13).get("Result")
						.toString()));
			}
		} else {
			salesMoney = mData.get("Sales").toString();
			// salesView.setText(salesMoney + " 彩豆");
			salesView.setText(addForeColorSpan(salesMoney));
		}
		// 奖池金额----
		Wins = mData.get("Balance").toString();
		if (lottID.equals("3") || lottID.equals("5") || lottID.equals("9") || lottID.equals("13")
				|| lottID.equals("39")) {
			// allmoneyView.setText(Wins + " 彩豆");
			// Log.v("kjinfodetail", "Wins= "+Wins);
			allmoneyView.setText(addForeColorSpan(Wins));
		} else if (lottID.equals("1") || lottID.equals("19")) {
			sfcAllMoney = mData.get("Balance").toString();
			// tv_sfcAllMoney.setText(sfcAllMoney + " 彩豆");
			// Log.v("kjinfodetail", "sfcAllMoney= "+sfcAllMoney);
			tv_sfcAllMoney.setText(addForeColorSpan(sfcAllMoney));
		} else {
			allmoneyView.setText("该彩种暂不支持奖池");
		}

		awardList = ConvertJsonToList.getList(mData.get("Wins").toString());
		for (int i = 0; i < awardList.size(); i++) {
			if (awardList.get(i).get("Name").equals("快乐星期天")) {
				awardList.remove(i);
				--i;
			}
		}
		adapter = new SimpleAdapter(KjinfoListDetail.this, awardList, R.layout.kjinfo_info_list, new String[] { "Name",
				"Count", "Money" }, new int[] { R.id.leve, R.id.winning, R.id.levemoney });

		kjinfo_info_lv1.setAdapter(adapter);

		kjinfo_info_lv2_awardList2 = getLOTZhongJiangTiaoJian();
		conditionAdapter = new KjInfoListAdapter(KjinfoListDetail.this, kjinfo_info_lv2_awardList2);
		kjinfo_info_lv2.setAdapter(conditionAdapter);
	}

	SimpleAdapter adapter;

	/**
	 * 文字颜色
	 */
	// private SpannableString addForeColorSpan(String colorStr) {
	// SpannableString spanString = new SpannableString(colorStr+" 彩豆");
	// ForegroundColorSpan span = new ForegroundColorSpan(R.color.red_ssqfont);
	// //red_ssqfont
	// spanString.setSpan(span, 0, colorStr.length(),
	// Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
	// // salesView.append(spanString);
	// return spanString;
	// }

	private Spanned addForeColorSpan(String colorStr) {
		return Html.fromHtml("<font color=#fe5052>" + colorStr + "</font> 彩豆");
	}

	private void setBtnOnClick(final int btnId) {
		Button btn = (Button) findViewById(btnId);
		btn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				kjLotDetail(btnId);
			}
		});
	}

	public boolean checkUserLogin() {
		// app_dltdto = (ApplicationBall) getApplication();
		if (!ApplicationData.getInstance().getLoginName().equals("")
				&& !ApplicationData.getInstance().getLoginPwd().equals("")
				|| !ApplicationData.getInstance().getUserID().equals("")) {
			return true;
		} else {
			return false;
		}
	}

	List<Map<String, Object>> kjinfo_info_lv2_awardList2 = new ArrayList<Map<String, Object>>();

	/**
	 * 获取lotType，及改变按钮背景
	 * 
	 * @param btnId
	 * @return
	 */
	public void kjLotDetail(int btnId) {
		// 恢复默认
		kjinfo_detail_bt_kjxq.setSelected(false);
		kjinfo_detail_bt_jjdz.setSelected(false);
		switch (btnId) {
		case R.id.kjinfo_detail_bt_kjxq:
			kjinfo_detail_bt_kjxq.setSelected(true);
			winning.setText("注数");

			kjinfo_info_lv1.setVisibility(View.VISIBLE);
			kjinfo_info_lv2.setVisibility(View.GONE);
			break;
		case R.id.kjinfo_detail_bt_jjdz:
			kjinfo_detail_bt_jjdz.setSelected(true);
			winning.setText("中奖条件");
			// 双色球等
			kjinfo_info_lv1.setVisibility(View.GONE);
			kjinfo_info_lv2.setVisibility(View.VISIBLE);
			break;
		}
	}

	KjInfoListAdapter conditionAdapter;

	/**
	 * 获取彩种中奖条件
	 * 
	 * @return
	 */
	public List<Map<String, Object>> getLOTZhongJiangTiaoJian() {
		List<Map<String, Object>> awardList2 = new ArrayList<Map<String, Object>>();
		// 双色球
		if (Integer.parseInt(lottID) == LOT_ID_SSQ) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("Name", "一等奖");
			map.put("condition", "6+1");
			map.put("Jiangjin", "浮动");
			awardList2.add(map);
			map = new HashMap<String, Object>();
			map.put("Name", "二等奖");
			map.put("condition", "6+0");
			map.put("Jiangjin", "浮动");
			awardList2.add(map);
			map = new HashMap<String, Object>();
			map.put("Name", "三等奖");
			map.put("condition", "5+1");
			map.put("Jiangjin", "3,000");
			awardList2.add(map);
			map = new HashMap<String, Object>();
			map.put("Name", "四等奖");
			map.put("condition", "5+0|4+1");// "5+0|4+1"
			map.put("Jiangjin", "200");
			awardList2.add(map);
			map = new HashMap<String, Object>();
			map.put("Name", "五等奖");
			map.put("condition", "4+0");// "4+0|3+1"
			map.put("Jiangjin", "10");
			awardList2.add(map);
			map = new HashMap<String, Object>();
			map.put("Name", "六等奖");
			map.put("condition", "2+1");// "2+1|1+1|0+1"
			map.put("Jiangjin", "5");
			awardList2.add(map);
		}

		// 大乐透
		if (Integer.parseInt(lottID) == LOT_ID_DLT) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("Name", "一等奖");
			map.put("condition", "5+2");
			map.put("Jiangjin", "浮动");
			awardList2.add(map);
			map = new HashMap<String, Object>();
			map.put("Name", "二等奖");
			map.put("condition", "5+1");
			map.put("Jiangjin", "浮动");
			awardList2.add(map);
			map = new HashMap<String, Object>();
			map.put("Name", "三等奖");
			map.put("condition", "5+0");// 5+0|4+2
			map.put("Jiangjin", "浮动");
			awardList2.add(map);
			map = new HashMap<String, Object>();
			map.put("Name", "四等奖");
			map.put("condition", "4+1");// 4+1|3+2
			map.put("Jiangjin", "200");
			awardList2.add(map);
			map = new HashMap<String, Object>();
			map.put("Name", "五等奖");
			map.put("condition", "4+0");// 4+0|3+1|2+2
			map.put("Jiangjin", "10");
			awardList2.add(map);
			map = new HashMap<String, Object>();
			map.put("Name", "六等奖");
			map.put("condition", "3+0");// "3+0|1+2|2+1|0+2"
			map.put("Jiangjin", "5");
			awardList2.add(map);
		}
		return awardList2;
	}

	// TitleBar标题栏
	public void TitleBar() {
		// Title信息(返回+Title)
		Button back = (Button) findViewById(R.id.top_title_back);
		back.setVisibility(View.VISIBLE);
		back.getBackground().setAlpha(255);// 透明度0~255透明度值 ，值越小越透明
		back.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				onKeyDown(KeyEvent.KEYCODE_BACK, null);
			}
		});
		topTitleView = (TextView) findViewById(R.id.top_title_info);
		// topTitleView.setText(lottName + "第" + Issue);
		if (lottName.contains("开奖")) {
			topTitleView.setText(lottName);
		} else {
			topTitleView.setText(lottName + "开奖");
		}
		Button refres = (Button) findViewById(R.id.top_title_refres);
		refres.setVisibility(View.GONE);
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			this.finish();
			// if(isBackToMF == true){
			//
			// ActivityManager am =
			// (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
			// List<RunningTaskInfo> list = am.getRunningTasks(100);
			// for (RunningTaskInfo info : list) {
			// if (info.topActivity.getPackageName().equals("com.playball.lottery") &&
			// info.baseActivity.getPackageName().equals("com.playball.lottery")) {
			// isAppRunning = true;
			// //find it, break
			// break;
			// }
			// }

			// Intent intent =
			// //getPackageManager().getLaunchIntentForPackage("com.playball.lottery");
			// new Intent(KjinfoListDetail.this,JddMainFrameActivity.class);
			// startActivity(intent);
			this.finish();
			// }else{
			// this.finish();
			// }
			return true;
		} else {
			return super.onKeyDown(keyCode, event);
		}
	};

	@Override
	public void finish() {
		// TODO Auto-generated method stub
		super.finish();
		SysApplication.getInstance().removeActivity(this);
	};

	class KjInfoListAdapter extends BaseAdapter {

		private LayoutInflater inflater = null;

		private List<Map<String, Object>> mData;

		public KjInfoListAdapter(Context context, List<Map<String, Object>> mData) {
			inflater = LayoutInflater.from(context);
			this.mData = mData;
		}

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return mData.size();
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public View getView(final int position, View convertView, ViewGroup parent) {
			// TODO Auto-generated method stub
			int lotIdInt = Integer.parseInt(lottID);

			ViewHolder holder = null;
			holder = new ViewHolder();

			LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
			layoutParams.gravity = Gravity.CENTER_VERTICAL;
			layoutParams.rightMargin = 5;

			// String redBTemp = mData.get(position).get("Ball").toString();
			// String blueBTemp =
			// mData.get(position).get("BlueBall").toString();
			String conditionTemp = mData.get(position).get("condition").toString();

			convertView = inflater.inflate(R.layout.kjinfo_info_list_ssq, null);
			holder.name = (TextView) convertView.findViewById(R.id.leve);
			holder.money = (TextView) convertView.findViewById(R.id.levemoney);
			holder.ballLayout = (LinearLayout) convertView.findViewById(R.id.kjinfo_item_ball_layout);

			String strname = mData.get(position).get("Name").toString();
			if (lotIdInt == LOT_ID_SSQ) {
				if (!strname.equals("四等奖") && !strname.equals("五等奖") && !strname.equals("六等奖")) {
					int r1 = Integer.parseInt(conditionTemp.split("\\+")[0]);
					for (int i = 0; i < r1; i++) {
						ImageView button = (ImageView) inflater.inflate(R.layout.kjinfo_item_ball_smallred, null);
						// button.setText(ball);
						holder.ballLayout.addView(button, layoutParams);
					}
					// String[] blueBall = blueBTemp.split(" ");
					int b1 = Integer.parseInt(conditionTemp.split("\\+")[1]);
					if (b1 != 0) {
						for (int i = 0; i < b1; i++) {
							ImageView button = (ImageView) inflater.inflate(R.layout.kjinfo_item_ball_smallblue, null);
							// button.setBackgroundResource(R.drawable.blueball_newssq_mid);//R.drawable.blueball1
							// button.setText(ball);
							holder.ballLayout.addView(button, layoutParams);
						}
					}
				}

				if (strname.equals("四等奖")) {
					View view = inflater.inflate(R.layout.kjinfo_info_list_ssq_sidengjiang, null);
					holder.ballLayout.setPadding(0, 0, 0, 0);
					holder.ballLayout.addView(view, layoutParams);
				}

				if (strname.equals("五等奖")) {
					View view = inflater.inflate(R.layout.kjinfo_info_list_ssq_wudengjiang, null);
					holder.ballLayout.setPadding(0, 0, 0, 0);
					holder.ballLayout.addView(view, layoutParams);
				}

				if (strname.equals("六等奖")) {
					View view = inflater.inflate(R.layout.kjinfo_info_list_ssq_liudengjiang, null);
					holder.ballLayout.setPadding(0, 0, 0, 0);
					holder.ballLayout.addView(view, layoutParams);
				}
			} else if (lotIdInt == LOT_ID_DLT) {
				if (!strname.equals("四等奖") && !strname.equals("五等奖") && !strname.equals("六等奖")) {
					int r1 = Integer.parseInt(conditionTemp.split("\\+")[0]);
					for (int i = 0; i < r1; i++) {
						ImageView button = (ImageView) inflater.inflate(R.layout.kjinfo_item_ball_smallred, null);
						// button.setText(ball);
						holder.ballLayout.addView(button, layoutParams);
					}
					// String[] blueBall = blueBTemp.split(" ");
					int b1 = Integer.parseInt(conditionTemp.split("\\+")[1]);
					if (b1 != 0) {
						for (int i = 0; i < b1; i++) {
							ImageView button = (ImageView) inflater.inflate(R.layout.kjinfo_item_ball_smallblue, null);
							// button.setBackgroundResource(R.drawable.blueball_newssq_mid);//R.drawable.blueball1
							// button.setText(ball);
							holder.ballLayout.addView(button, layoutParams);
						}
					}
				}

				if (strname.equals("四等奖")) {
					View view = inflater.inflate(R.layout.kjinfo_info_list_dlt_sidengjiang, null);
					holder.ballLayout.setPadding(0, 0, 0, 0);
					holder.ballLayout.addView(view, layoutParams);
				}

				if (strname.equals("五等奖")) {
					View view = inflater.inflate(R.layout.kjinfo_info_list_dlt_wudengjiang, null);
					holder.ballLayout.setPadding(0, 0, 0, 0);
					holder.ballLayout.addView(view, layoutParams);
				}

				if (strname.equals("六等奖")) {
					View view = inflater.inflate(R.layout.kjinfo_info_list_dlt_liudengjiang, null);
					holder.ballLayout.setPadding(0, 0, 0, 0);
					holder.ballLayout.addView(view, layoutParams);
				}
			}

			holder.name.setText(mData.get(position).get("Name").toString());
			holder.money.setText(mData.get(position).get("Jiangjin").toString());
			convertView.setTag(holder);

			return convertView;
		}

		class ViewHolder {
			TextView name;
			TextView money;
			LinearLayout ballLayout;
		}
	}
}